/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.aptech.business;

import com.aptech.DAO.IAccountTestDAO;
import com.aptech.DAO.ICommonDAO;
import com.aptech.domain.JPA.Event;
import com.aptech.DAO.IAccountDAO;
import com.aptech.DAO.ICategoryDAO;
import com.aptech.DAO.IEventDAO;
import com.aptech.DAO.IEventRequestDAO;
import com.aptech.DAO.IFaqDAO;
import com.aptech.DAO.INewsCategoryDAO;
import com.aptech.DAO.IPostDAO;
import com.aptech.DAO.ITopicDAO;
import com.aptech.domain.JPA.Account;
import com.aptech.domain.JPA.EventRequest;
import com.aptech.domain.model.AccountDO;
import com.aptech.domain.model.EventDO;
import com.aptech.domain.model.EventRequestDO;
import com.aptech.util.Converter;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.security.authentication.encoding.PasswordEncoder;

/**
 *
 * @author Admin
 */
public class BaseManager {
    private static Logger logger = Logger.getLogger(EventManager.class);
    protected IAccountDAO accountDAO;
    protected ICategoryDAO categoryDAO;
    protected IEventDAO eventDAO;
    protected IEventRequestDAO eventRequestDAO;
    protected IFaqDAO faqDAO;
    protected IPostDAO postDAO;
    protected ITopicDAO topicDAO;
    protected INewsCategoryDAO newsCategoryDAO;
    protected PasswordEncoder passwordEncoder;
    protected IAccountTestDAO accountTestDAO;
    protected ICommonDAO commonDAO;
    public INewsCategoryDAO getNewsCategoryDAO() {
        return newsCategoryDAO;
    }

    public void setNewsCategoryDAO(INewsCategoryDAO newsCategoryDAO) {
        this.newsCategoryDAO = newsCategoryDAO;
    }

    public String encodeString(String str) {
        return passwordEncoder.encodePassword(str, null);
    }

    /**
     * @return the accountDAO
     */
    public IAccountDAO getAccountDAO() {
        return accountDAO;
    }

    /**
     * @param accountDAO the accountDAO to set
     */
    public void setAccountDAO(IAccountDAO accountDAO) {
        this.accountDAO = accountDAO;
    }

    /**
     * @return the categoryDAO
     */
    public ICategoryDAO getCategoryDAO() {
        return categoryDAO;
    }

    /**
     * @param categoryDAO the categoryDAO to set
     */
    public void setCategoryDAO(ICategoryDAO categoryDAO) {
        this.categoryDAO = categoryDAO;
    }

    /**
     * @return the eventDAO
     */
    public IEventDAO getEventDAO() {
        return eventDAO;
    }

    /**
     * @param eventDAO the eventDAO to set
     */
    public void setEventDAO(IEventDAO eventDAO) {
        this.eventDAO = eventDAO;
    }

    /**
     * @return the eventRequestDAO
     */
    public IEventRequestDAO getEventRequestDAO() {
        return eventRequestDAO;
    }

    /**
     * @param eventRequestDAO the eventRequestDAO to set
     */
    public void setEventRequestDAO(IEventRequestDAO eventRequestDAO) {
        this.eventRequestDAO = eventRequestDAO;
    }

    /**
     * @return the faqDAO
     */
    public IFaqDAO getFaqDAO() {
        return faqDAO;
    }

    /**
     * @param faqDAO the faqDAO to set
     */
    public void setFaqDAO(IFaqDAO faqDAO) {
        this.faqDAO = faqDAO;
    }

    /**
     * @return the postDAO
     */
    public IPostDAO getPostDAO() {
        return postDAO;
    }

    /**
     * @param postDAO the postDAO to set
     */
    public void setPostDAO(IPostDAO postDAO) {
        this.postDAO = postDAO;
    }

    /**
     * @return the topicDAO
     */
    public ITopicDAO getTopicDAO() {
        return topicDAO;
    }

    /**
     * @param topicDAO the topicDAO to set
     */
    public void setTopicDAO(ITopicDAO topicDAO) {
        this.topicDAO = topicDAO;
    }

    /**
     * @return the passwordEncoder
     */
    public PasswordEncoder getPasswordEncoder() {
        return passwordEncoder;
    }

    /**
     * @param passwordEncoder the passwordEncoder to set
     */
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    /**
     * @return the accountTestDAO
     */
    public IAccountTestDAO getAccountTestDAO() {
        return accountTestDAO;
    }

    /**
     * @param accountTestDAO the accountTestDAO to set
     */
    public void setAccountTestDAO(IAccountTestDAO accountTestDAO) {
        this.accountTestDAO = accountTestDAO;
    }

    /**
     * @return the commonDAO
     */
    public ICommonDAO getCommonDAO() {
        return commonDAO;
    }

    /**
     * @param commonDAO the commonDAO to set
     */
    public void setCommonDAO(ICommonDAO commonDAO) {
        this.commonDAO = commonDAO;
    }
    protected EventDO getEvent(Event event) {
        final String LOCATION = "getEvent()";
        logger.debug(LOCATION + ":: BEGIN");
        try {
            EventDO result = new EventDO();
            List<EventRequestDO> eventRequestList = new ArrayList<EventRequestDO>();
            result = Converter.get(event, EventDO.class);
            for(EventRequest eventRequest : event.getEventRequests()) {
                EventRequestDO eventRequestDO = Converter.get(event.getEventRequests(), EventRequestDO.class);
                eventRequestList.add(eventRequestDO);
            }
            result.setEventRequests(eventRequestList);
            return result;
        } catch (Exception e) {
            logger.debug(e);  
        }
        return null;
    }
    protected List<EventDO> getEventList(List<Event> eventList) {
        final String LOCATION = "getEvent()";
        logger.debug(LOCATION + ":: BEGIN");
        try {
            List<EventDO> result = new ArrayList<EventDO>();
            for (Event event : eventList) {
                result.add(getEvent(event));
            }
            return result;
        } catch (Exception e) {
            logger.debug(e);  
        }
        return null;
    }
    protected AccountDO getAccount(Account account) {
        final String LOCATION = "getAccount()";
        logger.debug(LOCATION + ":: BEGIN");
        try {
           AccountDO result = Converter.get(account, AccountDO.class);
        } catch (Exception e) {
            logger.debug(e);  
        }
        return null;
    }


}
